package com.jbp.job;

import com.jbp.redis.RedisConfigService;
import com.jbp.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

/**奖池任务*/
//@Component
//@Configuration
public class LuckJob {
    @Autowired
    private RedisConfigService redisConfigService;
    @Autowired
    private PropertyService propertyService;

    @Autowired
    private LuckyUtil8 luckyUtil;

    @Scheduled(fixedDelay = 1000*60*60)
    public void refreshData(){
//        redisConfigService.removePattern("*");
//        redisConfigService.removePattern("user:new:*");

//        System.out.println("清奖池");
//        redisConfigService.removePattern("haoya:luck*");

//        System.out.println("生成奖池：" );
       /* String poolName = "haoya:luck:" + 20 + ":pool:A";
        Integer r_pool = (Integer) redisConfigService.get(poolName);
        int pool = r_pool != null ? r_pool : 0;
        pool += 40000;
        System.out.println("生成奖池：" + pool);
        redisConfigService.set(poolName, pool);*/


        /*String[] pools={"D","A","B","C"};
//        String[] pools={"A"};
        int[] prices = {20,1000};
        for (String poolName : pools) {
            for (int price : prices) {
                Integer r_pool = (Integer) redisConfigService.get("haoya:luck:" + price + ":pool:" + poolName);
                int pool = r_pool != null ? r_pool : 0;

                //奖池剩余礼物数量
                Integer r_giftCount = (Integer) redisConfigService.get("haoya:luck:" + price + ":giftcount:" + poolName);
                int giftCount = r_giftCount != null ? r_giftCount : 0;

                if (price==20) {
                    giftCount = 20000;
                } else {
                    giftCount = 800;
                }
                pool = (int) (giftCount * price * 1.15 );//+200000;
                pool += 20000;
                System.out.println("生成奖池：" + pool);
                redisConfigService.set("haoya:luck:" + price + ":pool:" + poolName, pool);
                redisConfigService.set("haoya:luck:" + price + ":giftcount:" + poolName, giftCount);
            }
        }*/
        //补池
        /*Integer r_patch_pool = (Integer) redisConfigService.get("haoya:luck:patchpool");
        int patchPool = r_patch_pool!=null ? r_patch_pool : 0;
//        patchPool += 120000;
        patchPool += 500000;
        redisConfigService.set("haoya:luck:patchpool", patchPool);*/
    }

    /**设置用户数据*/
//    @Scheduled(fixedDelay = 1000*60*60)
    public void setUserDate(){
        int user_id=1000050757;
        int price = 20;
        String poolEnd = ":"+user_id;
        String poolName = "D";

        redisConfigService.set("haoya:luck:"+price+":pool:"+poolName+poolEnd, (int)(20000*price*0.7d));
        redisConfigService.set("haoya:luck:"+price+":giftcount:"+poolName+poolEnd, 20000);

        //水池
        Integer r_pool = (Integer) redisConfigService.get("haoya:luck:"+price+":pool:"+poolName+poolEnd);
        int pool = r_pool!=null ? r_pool : 0;

        //奖池剩余礼物数量
        Integer r_giftCount = (Integer) redisConfigService.get("haoya:luck:"+price+":giftcount:"+poolName+poolEnd);
        int giftCount = r_giftCount!=null ? r_giftCount : 0;

        System.out.println("pool:"+pool);
        System.out.println("giftCount:"+giftCount);

       /* Integer r_pool = (Integer) redisConfigService.get("haoya:luck:" + 20 + ":pool:D");
        int pool = r_pool != null ? r_pool : 0;
        pool += 20000;
        System.out.println("生成奖池：" + pool);
        redisConfigService.set("haoya:luck:" + 20 + ":pool:D", pool);*/

    }
}

